# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgbase=python-ua-parser
pkgname=('python2-ua-parser' 'python-ua-parser')
_pkgname=ua-parser
pkgver=1.0.1
pkgrel=1
pkgdesc="Python port of Browserscope's user agent parser."
url='https://pypi.org/project/ua-parser/#files'
license=('APACHE')
arch=('any')
makedepends=('python2-setuptools' 'python-setuptools')
source=("https://files.pythonhosted.org/packages/source/${_pkgname::1}/$_pkgname/$_pkgname-$pkgver.tar.gz")
sha512sums=('4a117e5e1d9b0ff3a70f44e011f6990cf77c787f0244e95904858478de217c0784b168e1e43f3cb891406d6c9498c525d0219bd412201d6fb844a964a362259f')

prepare() {
  cp -a "$_pkgname-$pkgver"{,-2}
}

build() {
  cd "$_pkgname-$pkgver-2"

  python2 setup.py build

  cd "$srcdir/$_pkgname-$pkgver"

  python setup.py build
}

package_python2-ua-parser() {
  depends=('python2' 'python2-yaml')

  cd "$_pkgname-$pkgver-2"

  python2 setup.py install --prefix=/usr --root="$pkgdir" --optimize=1 \
    --skip-build

  find "$pkgdir" -type f -name '*.py' | xargs sed -i \
    's|#!/usr/bin/python2.5|#!/usr/bin/python2|'
  find "$pkgdir" -type f -name '*.py' | xargs sed -i \
    's|#!/usr/bin/env python|#!/usr/bin/env python2|'
}

package_python-ua-parser() {
  depends=('python' 'python-yaml')

  cd "$_pkgname-$pkgver"

  python setup.py install --prefix=/usr --root="$pkgdir" --optimize=1 \
    --skip-build

  find "$pkgdir" -type f -name '*.py' | xargs sed -i \
    's|#!/usr/bin/python2.5|#!/usr/bin/python|'
  find "$pkgdir" -type f -name '*.py' | xargs sed -i \
    's|#!/usr/bin/env python|#!/usr/bin/env python|'
}

